<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>电影管理</el-breadcrumb-item>
      <el-breadcrumb-item>电影列表</el-breadcrumb-item>
      <el-breadcrumb-item>管理剧照图片</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 剧照列表 -->
    <el-divider content-position="center">剧照列表</el-divider>

    <template v-if="thumbList">
      <div class="thumb-item" v-for="item in thumbList" :key="item.id">
        <el-image
          style="
            width: 160px;
            height: 120px;
            box-shadow: #0003 5px 5px 5px 0px;
            margin: 10px 20px 0px 0px;
          "
          :src="item.url"
          fit="cover"
        ></el-image>
        <i class="el-icon-error" @click="deleteThumb(item.id)"></i>
      </div>
    </template>
  </div>
</template>
<script>
export default {
  data() {
    return {
      movie_id: this.$route.params.movie_id,
      thumbList: null, // 绑定剧照列表
    };
  },
  methods: {
    /**
     * 删除剧照
     */
    deleteThumb(id) {
      this.$confirm("此操作将会删除该照片，是否继续进行", "提示", {
        confirmButtonText: "取消",
        confirmButtonText: "确定",
        type: "warning",
      }).then(() => {
        this.$http.MovieThumbApi.delete({ id }).then((res) => {
          console.log("删除剧照", res);
          if (res.data.code == 200) {
            this.loadThumbByMovieId();
          }
          this.$message({
            type: "success",
            message: "删除成功",
          });
        });
      });
    },
    /**
     * 通过电影ID加载查询剧照列表
     */
    loadThumbByMovieId() {
      this.$http.MovieThumbApi.listMovieById({ movie_id: this.movie_id }).then(
        (res) => {
          console.log(res, "加载剧照图片");
          this.thumbList = res.data.data;
        }
      );
    },
  },
  created() {
    this.loadThumbByMovieId();
  },
};
</script>

<style scoped>
.thumb-item {
  display: inline-block;
  position: relative;
}
.thumb-item i {
  position: absolute;
  right: 10px;
  top: 0px;
  font-size: 1.3em;
  display: none;
  cursor: pointer;
}
.thumb-item:hover i {
  display: block;
}
</style>
